<template>
	<view class="page-container">

		<v-tabs class="coupon-view-tab" v-model="tabCurrent" auto :tabs="tabGroup" :activeColor="activeColor" :lineColor="lineColor"
		 @change="clickTab">
		</v-tabs>

		<view class="order-group-wrapper">			
			<view class="order-group-wrapper__item" v-for="item in orderDatas" :key="item.id" @click="toDetail(item.order_sn)">
				<view class="hd-block">
					<view class="number">订单号{{item.order_sn}}</view>					
					<view class="state" v-if="item.status == 1">待付款</view>
					<view class="state" v-if="item.status == 2">待消费</view>
					<view class="state" v-if="item.status == 3">已关闭</view>
					<view class="state" v-if="item.status == 4">已退款</view>
					<view class="state" v-if="item.status == 5">已完成</view>	
					<view class="state" v-if="item.status == 6">待退款</view>
				</view>
				<view class="md-block">
					<view class="hd">
						<image class="hd" :src="item.product.image" mode="aspectFill"></image>
					</view>
					<view class="bd">
						<view class="title">{{item.product_name}}</view>						
						<view class="date" >出行日期：{{item.use_date}}</view>
						<view class="date" >上车地点：{{item.bycar_place}}</view>
						<view class="date" >上车时间：{{item.bycar_time}}</view>
					</view>
				</view>
				<view class="fd-block">
					<view class="total_price">&yen;{{(item.sell_price * item.num).toFixed(2)}}</view>					
					<view v-if="item.status == 1">
						<view class="default btn" >取消订单</view>
						<view class="default btn" >立即付款</view>
					</view>
					<view v-else-if="item.status == 2">
						<view class="default btn" >申请退款</view>					
					</view>					
					</view>					
				</view>				
			</view>				
		</view>
	</view>
</template>

<script>
	import {
		get_date_format
	} from '@/utils/utils.js'
	import {
		apiUrl
	} from '@/api/base.js'
	export default {
		components: {
		
		},
		data() {
			return {
				tabCurrent: 0,
				tabGroup: ['全部', '待付款', '待消费', '已完成','退款'],
				activeColor: "#2dbb55",
				lineColor: "#2dbb55",
				status: '',
				orderDatas: []				
			}
		},
		onLoad(options) {
			let cur = options.current;		
			if (cur == -1) {
				this.status = ''				
			} else if (cur == 0) {
				this.tabCurrent = 0;				
				this.status = 0
			} else if (cur == 1) {
				this.tabCurrent = 1;
				this.status = 1
			} else if (cur == 2) {
				this.tabCurrent = 2;
				this.status = 2
			} else if (cur == 3) {
				this.tabCurrent = 3;
				this.status = 5
			} else if (cur == 4) {
				this.tabCurrent = 4;
				this.status = 4
			} 
			this.getOrderList()
		},
		onShow() {
			if (uni.getStorageSync("userInfo")) {
				this.userInfo = uni.getStorageSync("userInfo")	
			}else{
				uni.navigateTo({
					url: '/pages/my/login'					
				});
			}
			this.getOrderList()
		},
		onReachBottom() {
			this.getOrderList()
		},
		methods: {
			toDetail(order_sn){				
				uni.navigateTo({
					url: '/pages/orders/detail?order_sn='+order_sn
				});
			},
			// 切换订单状态
			clickTab(e) {				
				this.orderDatas = [];
				if (e == 0) {
					this.status = ''
				} else if (e == 1) {
					this.status = 1
				} else if (e == 2) {
					this.status = 2
				} else if (e == 3) {
					this.status = 5
				} else if (e == 4) {
					this.status = 4
				}
				this.getOrderList()
			},

			// 获取订单列表
			getOrderList() {
				uni.request({
					url: apiUrl + "addons/car/order/getOrderList",
					data: {
						user_id:uni.getStorageSync("userInfo").user_id,
						status:this.status
					},
					method: "GET",
					success: (res) => {
						this.orderDatas=res.data.data
					},
					fail: (res) => {
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.coupon-view-tab {
		position: fixed;
		top: 88rpx;
		/* #ifndef H5 */
		top: 0;
		/* #endif */
		left: 0;
		right: 0;
		z-index: 100;
		border-bottom: 2rpx solid $uni-border-color;
		background-color: $uni-bg-color;
	}

	.order-group-wrapper {
		padding: 112rpx 24rpx 20rpx;

		&__item {
			margin-bottom: 20rpx;
			border-radius: 12rpx;
			background: #fff;

			.hd-block {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 24rpx;

				.number {
					color: $uni-text-color-grey;
					font-size: 22rpx;
				}

				.state {
					color: $uni-text-color-price;
					font-size: 24rpx;
				}
			}

			.md-block {
				display: -webkit-box;
				padding: 20rpx 24rpx;

				.hd {
					width: 180rpx;
					height: 180rpx;
					position: relative;
					overflow: hidden;
					border-radius: 12rpx;
					background: #e7e7e7;
				}

				.bd {
					-webkit-box-flex: 1;
					margin-left: 24rpx;

					.title {
						height: 40rpx;
						font-size: 28rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						line-clamp: 2;
						-webkit-box-orient: vertical;
					}

					.date,
					.sub {
						color: #999;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						margin-top: 10rpx;
						font-size: 24rpx;
					}
				}
			}

			.fd-block {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 24rpx 20rpx;

				.total_price {
					font-size: 28rpx;
					font-family: Arial;
				}

				.btn {
					display: inline-block;
					padding: 6rpx 20rpx;
					margin-right: 10rpx;
					border-radius: 60rpx;
					font-size: 24rpx;

					&:last-child {
						margin-right: 0;
					}

					&.default {
						border: 2rpx solid #d5d5d5;
						background: #fff;
					}
				}
			}
		}
	}
</style>
